# Contributor: Ian Bashford <ianbashford@gmail.com>
# Maintainer: Ian Bashford <ianbashford@gmail.com>
pkgname=xe-guest-utilities
pkgver=7.33.0
pkgrel=7
pkgdesc="XenServer guest tools"
url="https://github.com/xenserver/xe-guest-utilities"
arch="x86 x86_64 aarch64"
license="BSD-2-Clause"
makedepends="go udev"
subpackages="$pkgname-udev:udev:noarch $pkgname-openrc"
options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/xenserver/xe-guest-utilities/archive/v$pkgver.tar.gz
	$pkgname.initd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	#outdated dir breaks the build
	rm -r vendor
	go mod download
}

build() {
	make
}

package() {
	mkdir -p "$pkgdir"
	cp -ar "$builddir/build/stage/usr/" "$pkgdir/"
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/"$pkgname"
	install -Dm644 build/stage/etc/udev/rules.d/*.rules -t "$pkgdir"/usr/lib/udev/rules.d
}

udev() {
	depends=""
	pkgdesc="udev rules for CPU hotplugging when running as Xen DomU"
	install_if="$pkgname=$pkgver-r$pkgrel udev"

	amove usr/lib/udev/rules.d
}

sha512sums="
a81ddf5a12de19ac989400c9d2cf5383f870b9a87df0a1cf04d38686206ae07ca29f5fe5eb6446276266e666eb5e832f086c1d01a4623d77c52bc522d71019df  xe-guest-utilities-7.33.0.tar.gz
3e898b473f6e71ecc5b820717df0a460b31756b68f4bb9bf454df39f430e64ca5e33582c03bfea044d93f49937883fe9b6807c31dee72307750de670bfca8bcd  xe-guest-utilities.initd
"
